/**
 * @class This static class implements manipulation of <input type="radio"> html elements
 * @author erik 2/15/2009
 * @uses lib/Company/Company.js
 * @uses lib/Prototype/Prototype.js
 * @uses lib/Company/Utilities/Utils.js
 * @using Company.Error
 * @using Company.Error.ErrorHandler
 */

Company.UI.Form = {};


/**
* Return the value of the current selected radio in a radio button group
* @param {string} radioGroupName name of radio gropu
* @param {boolean} defaultToFirst If true, the first radio button's value is returned if none are selected
* @returns {String} value
*/
Company.UI.Form.getRadioValue = function(radioGroupName, defaultToFirst) {
	var form = document.forms[0];
	var value = null;
	var radioGroup = form.elements[radioGroupName];
	for (i = 0; i < radioGroup.length; i++) {
		if (defaultToFirst && value == null) value = radioGroup[i].value;
		if (radioGroup[i].checked) {
			value = radioGroup[i].value;
			break;
		}
	}
	return value;
}


/**
* Set the the currently selected radio in a radio button group
* @param {string} radioGroupName name of radio gropu
* @param {string} newValue Value of desired radio
*/
Company.UI.Form.setRadioValue = function(radioGroupName, value) {
	var form = document.forms[0];
	var radioGroup = form.elements[radioGroupName];
	for (i = 0; i < radioGroup.length; i++) {
		if (radioGroup[i].value == value) {
			radioGroup[i].checked = true;
		} else {
			radioGroup[i].checked = false;
		}
	}
}